package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.annotation.Query
import me.zhengjie.common.utils.JacksonUtil
import java.sql.Timestamp

/**
 * @author Kuki Wu
 * @date 2019-03-25
 */
@JsonTypeName("DeptQueryCriteria")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
class DeptQueryCriteria (
    @Query(type = Query.Type.IN, propName = "id")
    var ids: Set<Long>? = null,

    @Query(type = Query.Type.INNER_LIKE)
    var name: String? = null,

    @Query
    var enabled: Boolean? = null,

    @Query
    var pid: Long? = null,

    @Query(type = Query.Type.IS_NULL, propName = "pid")
    var pidIsNull: Boolean? = null,

    @Query(type = Query.Type.BETWEEN)
    var createTime: List<Timestamp?>? = null,

    @Query(type = Query.Type.GREATER_THAN, propName = "createTime")
    var startTime: Timestamp? = null,

    @Query(type = Query.Type.LESS_THAN, propName = "createTime")
        var endTime: Timestamp? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): DeptQueryCriteria? {
            val obj=JacksonUtil.parseObject(json, DeptQueryCriteria::class.java)!!
            return when(obj){
                is DeptQueryCriteria -> obj
                else -> null
            }
        }
    }

    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: DeptQueryCriteria?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}